export default function registerStart(lf) {
  lf.register('user', ({ RectNode, RectNodeModel, h }) => {
    class UserNode extends RectNode {
      getShape() {
        const { model } = this.props
        const { x, y, width, height, radius } = model
        const style = model.getNodeStyle()
        return h('g', {}, [
          h('rect', {
            ...style,
            x: x - width / 2,
            y: y - height / 2,
            rx: radius,
            ry: radius,
            width,
            height,
          }),
        ])
      }
    }

    class UserModel extends RectNodeModel {
      constructor(data, graphModel) {
        data.text = {
          value: (data.text && data.text.value) || '',
          x: data.x,
          y: data.y,
          dragable: false,
          editable: true,
        }
        super(data, graphModel)
        const style = super.getNodeStyle()
        const { r } = style
        super.r = r
        this.properties = data.properties || {}
      }

      getNodeStyle() {
        const style = super.getNodeStyle()
        const { properties } = this
        const { nodeStyle } = properties
        if (properties && nodeStyle) {
          if (nodeStyle.fill) {
            style.fill = nodeStyle.fill
          }
          if (nodeStyle.stroke) {
            style.stroke = nodeStyle.stroke
          }
        }

        return style
      }
    }

    return {
      view: UserNode,
      model: UserModel,
    }
  })
}
